﻿<!--#Include file = "includes/database.asp"-->
<!--#Include file = "includes/function.asp"-->
<!--#Include file = "includes/language.asp"-->
<!--#Include file = "includes/browser_page_encoding_inc.asp"-->
<!--#Include file = "includes/global_varaiable.asp"-->
<head>
<%
	If (CurrentUserLevel() < 1) then
		Response.Write(vbCrLf & "<script language=""JavaScript"">")
		Response.Write(vbCrLf & "window.location = 'login.asp'")
		Response.Write(vbCrLf & "</script>")
	End If
	
%>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language=JavaScript src="js/change.js">
</script>
<script language=JavaScript src="js/tw-sack.js">
</script>

<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>

<style type="text/css">
  @import url(calendar/calendar-win2k-1.css);
  .calendar .inf { font-size: 80%; color: #444; }
  .calendar .wn { font-weight: bold; vertical-align: top; }
</style>

<link href="css/default.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#a1a1a1">

<%

' status = 1: available
' status = 2: select
' status = 3: sold

dim book_status

function fixL(s)
		s = replace(s,"'","")
s= replace(s,"#'","")
fixL = replace(s,";'","")
end function

	loading =  fixL(Request("isLoading"))
	loadingRap =  fixL(Request("isLoadingRap"))
	giochieuID =  fixL(Request("GiochieuID"))
	rapID =  fixL(Request("RapID"))
	ngaychieu =  fixL(Request("Ngaychieu"))
	soghechon =  fixL(Request("Soghechon"))
	tenrap =  fixL(Request("Tenrap"))
	'gia = Request("Gia")
	Gia = ""
	loadNgaychieu =  fixL(Request("isLoadNgaychieu"))

	checkValid =  fixL(Request("checkValid"))
	soghechon =  fixL(Request("Soghechon"))
	soghehuy =  fixL(Request("Soghehuy"))

	filmID =  fixL(Request("FilmID"))
	strId =  fixL(Request("id"))
	if filmID = "" and strId <> "" then
		filmID = strId
	end if

	
	soghechon = Replace(soghechon, " ", "")
	maxY = 0
	
	set rs = CreateObject("ADODB.Recordset")
	strSQL = "SELECT ParamID, Paramname, ParamValue FROM THAMSO"
	rs.Open strSQL, adoCon
	While not rs.EOF
		strParamname = "" & rs("Paramname")
		if strParamname = "BOOKING_HOUR_BEFORE" then
			strBeforeHour = "" & rs("ParamValue")
		elseif strParamname = "BOOKING_HOUR_AFTER" then
			strAfterHour = "" & rs("ParamValue")
		end if

	rs.MoveNext
	Wend
	rs.Close
	set rs = Nothing
	
	if rapID <> "" and ngaychieu <> "" and giochieuID <> "" then

		set rs = CreateObject("ADODB.Recordset")
		strSQL = "SELECT TOP 1 a.FilmId, a.RoomID, a.SessionID, a.DayShow, c.RoomName, a.Price, b.Title, c.Width FROM SUATCHIEU a INNER JOIN CHITIETPHIM b ON a.FilmId = b.FilmID INNER JOIN PHONGCHIEU c ON a.RoomID = c.RoomID WHERE a.RoomID = " & rapID & " AND a.SessionID = " & giochieuID & " AND convert(char(10), a.DayShow, 101) = '" & ngaychieu & "'"
		rs.Open strSQL, adoCon
		While not rs.EOF
			tenphim = rs("Title")
			maxY = rs("Width")
			Gia = "" & rs("Price")
		rs.MoveNext
		Wend
		rs.Close
		set rs = Nothing
	end if

%>
<center>

<table border="0" width="1000" cellspacing="0" cellpadding="0">
	<tr>
	    <td align="center" valign="top">
	
			<table border="0" cellspacing="0" cellpadding="0" id="table18">
			
			<tr height="33">
				<td width="22" height="33" background="images/up_left.png"></td>
				<td width="100%" height="33" background="images/up_body.png"></td>
				<td width="22" height="33" background="images/up_right.png"></td>

			</tr>
						
			<tr>
				<td width="22" align="left" valign="top" background="images/left_body.png">
				<img border="0" src="images/left_body.png" ></td>
				<td width="100%" align="left" valign="top" background="images/bg.gif">
				
			
					<!--Noi dung-->
					<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table14">
						
					<!-- here here here here here here -->
						
						<tr><td valign="top" align="center">
						<img src="images/banner_mini.png" border="0">
						</td></tr>
						
						<tr><td valign="top" align="center">
						<img src="images/gach_yellow.gif" width="600" height="4" />
						<br><br>
						<div align="right" style="margin-right: 100px;">
						<font style="color:#99ff00; font-size: 10pt;">Xin chào <%=Session("StaffFullName")%> - <a href="logout.asp" style="text-decoration: none;">Đăng xuất</a></font></div>
						</td></tr>
						
						<!-- status -->
						<tr><td align="center">
						<iframe src="status.asp" frameborder=no scrolling=no width="800" height="21" name="status" id="status"></iframe>
						</td></tr>
					<!-- form chon phim -->
						
						<tr><td align="center">
						
							<table border="0" cellpadding="2" width="100%" id="table1">
							<tr>
								<td valign="middle">		
								<form name="formChonPhim" method="post" action="default.asp">
								
								<%
									set rs = CreateObject("ADODB.Recordset")
																		
									strSQL = "SELECT distinct a.FilmID, a.Title FROM ( CHITIETPHIM a INNER JOIN SUATCHIEU c ON a.FilmID = c.FilmId) Inner join GIOCHIEU b ON c.SessionID = b.SessionID  WHERE  "
									strSQL = strSQL & " dateadd(mi, b.MinuteStart, dateadd(hh, b.HourStart, DayShow) ) <=  dateadd(hh, " &  strBeforeHour  & ", convert(char(8), getdate(), 112))  AND dateadd(mi, b.MinuteStart, dateadd(hh, b.HourStart, DayShow) ) >= dateadd(hh," & strAfterHour & ",getdate()) "
  								    strSQL = strSQL & "  ORDER BY Title"

									rs.Open strSQL, adoCon
									While not rs.EOF
										strFilmID = "" & rs("FilmID")
										if filmID = strFilmID then
								%>
								<a href="def.ajax.asp?cmd=onChangedRapID&FilmID=<%=strFilmID%>" class="echannel" name="FilmID" target="rap" onclick="update_status()"><%=EncodeHtml(rs("Title"))%></a><br><br>
								<%
										else
								%>
								<a href="def.ajax.asp?cmd=onChangedRapID&FilmID=<%=strFilmID%>" class="echannel" name="FilmID" target="rap" onclick="update_status()"><%=EncodeHtml(rs("Title"))%></a><br><br>
								<%
										end if
								
									rs.MoveNext
									Wend
									rs.Close
									set rs = Nothing
								%>
								
								<br>
								<!-- lich -->
								<!--<div style="float: left; margin-left: 1em; margin-bottom: 1em;" id="calendar-container"></div>-->

								<script type="text/javascript">
								  function dateChanged(calendar) {
									// Beware that this function is called even if the end-user only
									// changed the month/year.  In order to determine if a date was
									// clicked you can use the dateClicked property of the calendar:
									if (calendar.dateClicked) {
									  // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
									  var y = calendar.date.getFullYear();
									  var m = calendar.date.getMonth();     // integer, 0..11
									  var d = calendar.date.getDate();      // integer, 1..31
									  // redirect...
									  window.location = "/" + y + "/" + m + "/" + d + "/index.php";
									}
								  };

								  Calendar.setup(
									{
									  flat         : "calendar-container", // ID of the parent element
									  flatCallback : dateChanged           // our callback function
									}
								  );
								</script>
								<!-- het lich -->	
								</td>
								<td width="10">&nbsp;</td>
								
								<td valign="middle">
								<iframe name="rap" frameborder=no width="190">Vui lòng chọn phim</iframe>
								</td>
								
								<td width="10">&nbsp;</td>
								
								<td valign="middle">
								<iframe name="ngaychieu" frameborder=no width="200">Vui lòng chọn rạp</iframe>
								</td>
								
								<td width="10">&nbsp;</td>
								
								<td valign="middle">
								<iframe name="suatchieu" frameborder=no width="200">Vui lòng chọn ngày chiếu</iframe>
								</td>
							</tr>
							
							<tr>
								<td colspan="7">
								<input type="hidden" name="FilmID" value="<%=Session("filmID")%>"/>
								<input type="hidden" name="RapID" value="<%=Session("rapID")%>" />
								<input type="hidden" name="Ngaychieu" value="<%=Session("ngaychieu")%>" />
								<input type="hidden" name="GiochieuID" value="<%=Session("giochieuID")%>" />
								&nbsp;
								<%
								If (Session("OK") = "true") then
								%>
								<center><input type="submit" value="Xem chỗ" onclick="reset_status()"></center>
								<%
								end if
								%>
								</form>
								</td>
							</tr>
							</table>					
						</td></tr>
						
					<!-- het form chon film -->
					
					<%
            	
                  		if rapID = "" then
            			rapID = "1"
            		end if

            		set rs = CreateObject("ADODB.Recordset")
            		strSQL = " SELECT TOP 1 RoomID, RoomName, Width FROM PHONGCHIEU WHERE RoomID = " & rapID
            		rs.Open strSQL, adoCon
					While not rs.EOF
						strTenRap = rs("RoomName")
						maxY = rs("Width")
					rs.MoveNext
					Wend
					rs.Close
					set rs = Nothing

					%>
					
					
					<!-- thong tin chon -->
					
					<tr><td align="center">
					<font style="font-size:11pt;">Phim: <font color="#99cc00"><%=tenphim%></font>, Rạp: <font color="#99cc00"><%=rapID%></font>, Ngày chiếu: <font color="#99cc00"><%=ngaychieu%></font>, Suất chiếu: <font color="#99cc00"><%=Session("giochieu")%></font><br></font>
					<!-- Phim: <%=filmid%>, Rạp: <%=rapid%>, Ngày chiếu: <%=ngaychieu%>, Suất chiếu: <%=giochieuid%>-->
					</td></tr>
						
					<!-- ghi chu mau ghe -->
						
						<tr><td align="center">
						<table border="0" cellpadding="2" width="50%">
							<tr>
							<td width="20">
							<img src="images/box_green.gif" />
							</td>
							<td width="160">Vị trí ghế trống
							</td>

							<td width="20">
							<img src="images/box_yellow.gif"  />
							</td>
							<td width="160">Vị trí ghế đang chọn
							</td>
								
							<td width="20">
							<img src="images/box_pink.gif" />
							</td>
							<td width="160">Vị trí ghế đã được bán
							</td>
								
							</tr>
						</table>
						</td></tr>
						
					<!-- het ghi chu mau ghe -->
						
					<!-- xuat so do rap khi co du lieu -->
						
					<%
					If rapID <> "" and giochieuID <> "" and maxY > 0 then
					%>
					
					<tr>
					<td align=center height="22" class="echannel">
					<font color="#FF8400" style="font-size:14pt;">Sơ đồ ghế:&nbsp; <%= EncodeHtml(strTenRap) %> </font></td>
					</tr>
					
					<tr>
					<td align=center height="77">
					
					<table border="0" cellpadding="0" cellspacing="0" width="800" id="table11">
							<tr>
								<td width="57"><img src="images/entryleft.gif" width="57" height="77" /></td>
								<td bgcolor="#4E525E">
								<p align="center"><img src="images/manhinh.gif" width="306" height="39" /></td>
								<td width="47"><img src="images/entryright.gif" width="47" height="77" /></td>
							</tr>
						</table>					
					
					<!-- khu vuc so do ghe -->
						
						<table width="800" bgcolor="#4E525E">
						<tr><td>
					
						<div align="center">
						<form name="formBooking" method="post" action="def_confirm.asp">

							<input type="hidden" name="FilmID" value="<%=filmID%>"/>
							<input type="hidden" name="isLoading" value="false"/>
							<input type="hidden" name="RapID" value="<%=rapID%>" />
							<input type="hidden" name="GiochieuID" value="<%=giochieuID%>" />
							<input type="hidden" name="Ngaychieu" value="<%=ngaychieu%>" />
							<input type="hidden" name="Gia" value="<%=Gia%>" />
							<input type="hidden" name="Tenphim" value="<%=tenphim%>" />
							<input type="hidden" name="TenRap" value="<%=strTenRap%>" />

							<table border="0" cellspacing="0" cellpadding="0">
							<%
								if GiochieuID = null or GiochieuID = "" then  giochieuID=0 end if
					  			set rs1 = CreateObject("ADODB.Recordset")											

														
								strSQL = " select a.DayShow, a.SessionID, a.RoomID  from SUATCHIEU a, GIOCHIEU b where a.SessionID = b.SessionID and a.DayShow=convert(nvarchar,'" & ngaychieu & "',112)  and a.SessionID=" & giochieuID & "  and  a.RoomID ='" & rapID & "' " 
								strSQL = strSQL & "  AND dateadd(mi, b.MinuteStart, dateadd(hh, b.HourStart, DayShow) ) <= DATEADD(hh, " &  strBeforeHour  & ", getdate()) AND dateadd(mi, b.MinuteStart, dateadd(hh, b.HourStart, DayShow) ) >= dateadd(hh," &  strAfterHour  & ",getdate()) "

								rs1.Open strSQL, adoCon							

								'Neu co xuat chieu
								if not (rs1.eof) then					
									set rs = CreateObject("ADODB.Recordset")
									strSQL = " select b.RoomID, b.SeatX, b.SeatY, a.Status, b.PointX , b.PointY, b.Type, b.Value, a.StaffId from BANVE a right outer join GHE b  "    
									strSQL  = strSQL  & " on a.RoomID = b.RoomID and a.SeatX = b.SeatX and a.SeatY = b.SeatY  and  a.DayShow=convert(nvarchar,'" & ngaychieu & "',112) and a.SessionID=" & giochieuID & " where b.RoomID ='" & rapID & "' " 
									strSQL  = strSQL  & "  order by b.PointX,  b.PointY "
									'Response.Write "[[SQL 1: " & strSQL  & "]]"
								'----------------------
								
								
								rs.Open strSQL, adoCon
								couter =0
								tempX = 0
								While not rs.EOF
									loai = rs("Type")

									toadoX = rs("PointX")
									toadoY = rs("PointY")
									trangthai = rs("Status")
									if isnull(trangthai) then trangthai=""
									
									if toadoY = 1 then 
  							%>
  								<tr height="21">
  							<%		end if 
  									if loai = 3 then
  							%>	
  									<TD width=21>&nbsp;</TD>
							<%
									elseif loai = 2 then
							%>
								<TD class=newshometitle vAlign=center align=middle width=21><FONT color=#ff6c00><SPAN style="FONT-SIZE: 8pt"><% Response.Write(rs("Value"))%></SPAN></FONT></TD>
							<%
									elseif loai = 1 then
										sogheX = rs("SeatX")
										sogheY = rs("SeatY")
										
										strTrangthai = "" & trangthai
										if strTrangthai = "" then
											trangthai = 1
											book_status = "booking_status_" & trangthai
										
										end if
										
										'response.write(trangthai)
										
										if trangthai = 1 then
										book_status = "booking_status_" & trangthai
							%>
								<TD id="td_<%=toadoX%>_<%=toadoY%>" onclick="onClick(<%=toadoX%>,<%=toadoY%>,<%=sogheX%>,<%=sogheY%>)" class="<%=book_status%>" valign=center align=middle width="21" style="cursor:hand"><%=rs("Value") %></TD>
							<%			
										elseif trangthai = 3 then
										book_status = "booking_status_" & trangthai
									
							%>
								<TD id="td_<%=toadoX%>_<%=toadoY%>" class="<%=book_status%>" valign=center align=middle width="21" style="cursor:hand"><%=rs("Value") %></TD>						
							<%			
										end if
										
									end if
			
									if toadoY = maxY then %>
								</tr>
							<%		end if
								rs.MoveNext
								Wend
								rs.Close
								set rs = Nothing
							
							'HungTQ---------------------------
							end if
							rs1.Close
							set rs1 = Nothing
							'-----------------------------
								
								
							%>
							</table>
							</form></div>
  						</td></tr>
						</table>
											
						<!-- het khu vuc so do ghe -->
						
						<table border="0" cellpadding="0" cellspacing="0" width="800" id="table12">
							<tr>
								<td width="24"><img src="images/datvedown1.gif" width="24" height="10" /></td>
								<td bgcolor="#4E525E">
								<img border="0" src="images/1.gif" width="1" height="1"></td>
								<td width="24"><img src="images/datvedown2.gif" width="24" height="10" /></td>
							</tr>
						</table>
						
					</td>
					</tr>
					
					<tr>
					<td align=center height="30">
						<input type="hidden" value="1" name="status"> 
						<input type="button" value="Đồng ý" name="B2" onclick="onSubmit()" style="font-family: Arial; font-size: 8pt; font-weight: bold">
						<!--<input type="submit" value="Làm lại" name="B1" style="font-family: Arial; font-size: 8pt; font-weight: bold">-->
						
					</td>
					</tr>
					
			  	</div>
			  
            	<!-- ket thuc xuat so do rap khi co du lieu -->
				
				<!-- xuat so do rap khi khong co du lieu -->
				
				<%
            	else
                  		if rapID = "" then
            			rapID = "1"
            		end if

            		set rs = CreateObject("ADODB.Recordset")
            		strSQL = " SELECT TOP 1 RoomID, RoomName, Width FROM PHONGCHIEU WHERE RoomID = " & rapID
            		rs.Open strSQL, adoCon
					While not rs.EOF
						strTenRap = rs("RoomName")
						maxY = rs("Width")
					rs.MoveNext
					Wend
					rs.Close
					set rs = Nothing

				%>
				
				<tr>
					<td align=center height="35">
						<font color="#FF8400" style="font-size:14pt;">Sơ đồ ghế:&nbsp; <%= EncodeHtml(strTenRap) %></font>
					</td>
				</tr>
				
				<tr>
					<td align=center >
											
						<table border="0" cellpadding="0" cellspacing="0" width="800" id="table11">
							<tr>
								<td width="57"><img src="images/entryleft.gif" width="57" height="77" /></td>
								<td bgcolor="#4E525E">
								<p align="center"><img src="images/manhinh.gif" width="306" height="39" /></td>
								<td width="47"><img src="images/entryright.gif" width="47" height="77" /></td>
							</tr>
						</table>
						
						<!-- khu vuc so do ghe -->
						
						<table width="800" bgcolor="#4E525E">
						<tr><td>
						
							<div align="center">
							
							<table width="624" border="0" cellspacing="0" cellpadding="0" id="table13">

							<%
								set rs = CreateObject("ADODB.Recordset")
								strSQL = " SELECT RoomID, PointX, PointY, SeatX, SeatY, Value, Type FROM GHE WHERE RoomID = " & rapID & " ORDER BY PointX, PointY "
								
				        		rs.Open strSQL, adoCon
								While not rs.EOF
									loai = rs("Type")
									toadoX = rs("PointX")
									toadoY = rs("PointY")
																	
									if toadoY = 1 then 

  							%>
  								<tr height="21">
  							<%		end if 
  									if loai = 3 then
  							%>	
  									<TD width=21>&nbsp;</TD>
							<%
									elseif loai = 2 then
							%>
								<TD class=newshometitle vAlign=center align=middle width=21><FONT color=#ff6c00><SPAN style="FONT-SIZE: 8pt"><%=rs("Value")%></SPAN></FONT></TD>
							<%
									elseif loai = 1 then
										sogheX = rs("SeatX")
										sogheY = rs("SeatY")
										
										
							 %>
								<TD id="td_<%=toadoX%>_<%=toadoY%>" class="booking_status_1" valign=center align=middle width="21" style="cursor:hand"><%=rs("Value")%></TD>
							<%
									end if
									if toadoY = maxY then


	 %>
								</tr>
							<%		end if
								rs.MoveNext
								Wend
								rs.Close
								set rs = Nothing
							%>
  							</table> 
						
						</div>
						
						</td></tr>
						</table>

							<!-- het khu vuc so do ghe -->
						
						<table border="0" cellpadding="0" cellspacing="0" width="800" id="table12">
							<tr>
								<td width="24"><img src="images/datvedown1.gif" width="24" height="10" /></td>
								<td bgcolor="#4E525E">
								<img border="0" src="images/1.gif" width="1" height="1"></td>
								<td width="24"><img src="images/datvedown2.gif" width="24" height="10" /></td>
							</tr>
						</table>
						
					</td>
				</tr>
									 
					<%
						end if
					%>
				
				<!-- ket thuc xuat so do rap khi khong co du lieu -->
						
					<!-- end end end end end end end -->
					</table>	
					<!-- Het noi dung -->
	
				</td>
				<td width="22" align="left" valign="top" background="images/right_body.png">&nbsp;</td>

			</tr>
			<tr>
				<td height="18" align="left" valign="top"><img src="images/down_left.png" width="22" height="18" /></td>
				<td height="18" align="left" valign="top" background="images/down_body.png"></td>
				<td width="22" height="18" align="left" valign="top"><img src="images/down_right.png" width="22" height="18" /></td>
			</tr>
			</table>          
		</td>
	</tr>
                          
</table>


<script language="javascript">

	function onClick(x, y, sogheX, sogheY)
	{
		var ctrlName = "td_" + x + "_" + y;
		var ctrl = document.getElementById(ctrlName);

		//var str = ctrl.innerText;//it just can be used for ie
		//it can be used for both ie and firefox
		var str = "";
		var temp = ctrl.innerHTML;
		var i = temp.indexOf('<');
		if (i >= 0) {
			str= temp.substring(0, i);
		}
		else {
			str = temp;
		}

		var str2 = new String(ctrl.innerHTML);
		if (str2.length < 3) {
			ctrl.className = "booking_status_2";
			ctrl.innerHTML = str  + "<input type=\"hidden\" value=\"" + sogheX + "_" + sogheY +  "\" name=\"Soghechon\"/>"
		}
		else {
			ctrl.className = "booking_status_1";
			ctrl.innerHTML = str;
		}
	}
	
	function onSubmit() {
    	<%If Session("StaffID") <> "" then%>
    		
	        		formBooking.isLoading.value = true;
					formBooking.submit();
	        	

		<%else%>
			alert("Vui lòng đăng nhập lại!");
			window.location = 'login.asp';
		<%end if%>
	}

	function reset_status() {
	<%
		if Session("status")="4" then Session("status")="0"
		Session("OK") = ""
	%>
	}
	
		
	function update_status() {
	 //parent.frames['status'].src='status.asp';
	 document.getElementById('status').src='status.asp';
	}
</script>